package com.kr.aia.powerrp.setting;
 
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.kr.aia.powerrp.db.CustomerInfoVO;
import com.kr.aia.powerrp.R;
 
public class CustomerListAdapter extends ArrayAdapter<CustomerInfoVO> {
 
    private Context context;
    private int layoutResourceId;
    private ArrayList<CustomerInfoVO> data;
    
    private int curPosition = -1;
    //public ImageLoader imageLoader;
 
    public CustomerListAdapter(Context context, int layoutResourceId, ArrayList<CustomerInfoVO> d) {
    	super(context, layoutResourceId, d);
    	this.context = context;
    	this.layoutResourceId = layoutResourceId;
        this.data=d;
        //imageLoader=new ImageLoader(activity.getApplicationContext());
    }
 
    public int getCount() {
        return data.size();
    }
 
    
    public CustomerInfoVO getItem(int position) {
        return data.get(position);
    }
    
    
    public void setSelectedItem(int position){
    	this.curPosition = position;
    }
 
    public long getItemId(int position) {
        return position;
    }
 
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(vi == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            vi = inflater.inflate(layoutResourceId, parent, false);
        }
            
        CustomerInfoVO curItem = super.getItem(position);
        if(curItem != null){
            TextView contact_name = (TextView)vi.findViewById(R.id.contact_name); // title
            TextView contact_phoneno = (TextView)vi.findViewById(R.id.contact_phoneno); // artist name
            
            contact_name.setText(curItem.getCustomerName());
            contact_phoneno.setText(curItem.getCustomerPhoneNo());
            
            
            if(curItem.isSelected){
            	vi.setBackgroundResource(R.drawable.gradient_bg_hover);
    		}else{
    			vi.setBackgroundResource(R.drawable.gradient_bg);
    		}
            
        }
        
        return vi;
    }
}